package com.example.carapi.web;

import com.example.carapi.bean.User;
import com.example.carapi.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/test")
public class TestController {
    @Autowired
    private UserService userService;

    @GetMapping(value = "/user")
    public Map<String, String> userServiceTest() {
        Map<String, String> map = new HashMap<>();

        User user = new User(6L, "initial_username", "initial_password", "admin");
        userService.addUserWithId(user);

        List<User> list = userService.getUsers();

        System.out.println("第一次添加后，user表中所有数据：");
        StringBuilder s1 = new StringBuilder();
        for (User u : list) {
            s1.append(u + "    ");
            System.out.println(u);
        }
        map.put("1.第一次添加后，user表中所有数据：", s1.toString());
        System.out.println("--------------------------------");

        System.out.println("获取添加的user内容：");
        user = userService.getUserById(6L);
        System.out.println(user);
        map.put("2.获取添加的user内容", user.toString());
        System.out.println("--------------------------------");

        System.out.println("更改后的user内容为：");
        user.setUsername("update_username");
        user.setPassword("update_password");
        user.setRole("guest");
        userService.updateUser(user);
        System.out.println(userService.getUserById(6L));
        map.put("3.更改后的user内容为", userService.getUserById(6L).toString());
        System.out.println("--------------------------------");

        System.out.println("更改后的user表中所有数据：");
        list = userService.getUsers();
        StringBuilder s2 = new StringBuilder();
        for (User u : list) {
            s2.append(u + "    ");
            System.out.println(u);
        }
        map.put("4.更改后的user表中所有数据", s2.toString());
        System.out.println("--------------------------------");

        userService.deleteUserById(6L);

        System.out.println("删除添加的user后，user表中所有数据：");
        StringBuilder s3 = new StringBuilder();
        list = userService.getUsers();
        for (User u : list) {
            s3.append(u + "    ");
            System.out.println(u);
        }
        map.put("5.删除添加的user后，user表中所有数据", s3.toString());

        return map;
    }

    @Autowired
    private CarBrandService carBrandService;

    @GetMapping(value = "/carBrand")
    public Map<String, String> carBrandServiceTest() {
        // TODO: to test CarBrandService API
        return null;
    }

    @Autowired
    private CarConfigService carConfigService;

    @GetMapping(value = "/carConfig")
    public Map<String, String> carConfigServiceTest() {
        // TODO: to test CarConfigService API
        return null;
    }

    @Autowired
    private CarLikeService carLikeService;

    @GetMapping(value = "/carLike")
    public Map<String, String> carLikeServiceTest() {
        // TODO: to test CarLikeService API
        return null;
    }

    @Autowired
    private CarModelService carModelService;

    @GetMapping(value = "/carModel")
    public Map<String, String> carModelServiceTest() {
        // TODO: to test CarModelService API
        return null;
    }

    @Autowired
    private CarSeriesService carSeriesService;

    @GetMapping(value = "/carSeries")
    public Map<String, String> carSeriesServiceTest() {
        // TODO: to test CarSeriesService API
        return null;
    }
}
